<template>
    <div>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column

                    prop="id"
                    label="问题编号"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="username"
                    label="用户名"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="title"
                    label="问题标题"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="content"
                    label="问题内容"
                    width="250">
            </el-table-column>
            <el-table-column
                    prop="ispast"
                    label="是否过审(1:是 0:否)"
                    width="80">
            </el-table-column>
            <el-table-column
                    prop="createtime"
                    label="创建时间"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="updatetime"
                    label="更新时间"
                    width="200">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="是否过审"
                    width="150"
            >
                <template slot-scope="scope">
                    <el-button type="success" @click="past(scope.row)" icon="el-icon-check" size="small" circle></el-button>
                    <el-button type="danger" @click="fail(scope.row)" icon="el-icon-close" size="small" circle></el-button>

                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                layout="prev, pager, next"
                :page-size=pageSize
                :total="total"
                :current-page=currentPage
                @current-change=page>
        </el-pagination>
    </div>
</template>

<script>
    export default {
        methods: {
            past(row) {
                const _this = this;
                if (row.ispast == 1){
                    _this.$message("此问题已经通过审核")
                }else {
                    axios.put("http://localhost:8181/consult/pastQ/" + row.id).then(function (resp) {
                        if (resp.data.code == 200) {
                            _this.$alert('问题' + row.content + ' 审核通过', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    window.location.reload();
                                }
                            });
                        }
                    })
                }
            },
            fail(row) {
                const _this = this;
                if (row.ispast == 0) {
                    _this.$message("此问题原本就不通过审核")
                } else {
                    axios.put("http://localhost:8181/consult/failQ/" + row.id).then(function (resp) {
                        if (resp.data.code == 200) {
                            _this.$alert('问题' + row.content + ' 审核不通过', '消息', {
                                confirmButtonText: '确定',
                                callback: action => {
                                    window.location.reload();
                                }
                            });
                        }
                    })
                }
            },
            page(currentPage){
                const _this = this
                axios.get("http://localhost:8181/manage/listQ?currentPage="+currentPage).then(function (resp) {
                    _this.tableData = resp.data.data.records
                    _this.total = resp.data.data.total
                    _this.currentPage = resp.data.data.current
                    _this.pageSize = resp.data.data.size
                })
            }
        },
        created() {
            const _this = this
            axios.get("http://localhost:8181/manage/listQ").then(function (resp) {
                _this.tableData = resp.data.data.records
                _this.total = resp.data.data.total
                _this.currentPage = resp.data.data.current
                _this.pageSize = resp.data.data.size

            })

        },
        data() {
            return {
                total: null,
                pageSize: null,
                currentPage: null,
                tableData: [{
                    id: '2016-05-02',
                    username: '王小虎',
                    content: '上海',
                    ispast: '普陀区',
                    createtime: 200333,
                    updatetime: '时间',
                }]
            }
        }
    }
</script>

<style scoped>

</style>